package com.model.装饰器;

// 组件接口
interface Coffee {
    double getCost();
    String getDescription();
}

// 具体组件
class SimpleCoffee implements Coffee {
    public double getCost() { return 1.0; }
    public String getDescription() { return "普通咖啡"; }
}

// 装饰器抽象类
abstract class CoffeeDecorator implements Coffee {
    protected Coffee decoratedCoffee;
    public CoffeeDecorator(Coffee coffee) {
        this.decoratedCoffee = coffee;
    }
}

// 具体装饰器：加牛奶
class MilkDecorator extends CoffeeDecorator {
    public MilkDecorator(Coffee coffee) {
        super(coffee); // 调用父子的构造函数
    }
    public double getCost() {
        return decoratedCoffee.getCost() + 0.5;
    }
    public String getDescription() {
        return decoratedCoffee.getDescription() + "+牛奶";
    }
}

// 使用示例
//Coffee coffee = new MilkDecorator(new SimpleCoffee());
//System.out.println(coffee.getDescription()); // 输出：普通咖啡+牛奶
//        System.out.println(coffee.getCost());        // 输出：1.5

